package com.xy.xymall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author XY
 * @version 1.0
 * @date 2020/10/22 15:16
 * @Description 配置spring session 子域，序列化方式等
 */
@Configuration
public class MySessionConfig {

    /**
     * @author XY
     * @date 2020/10/22 15:18
     * @return org.springframework.session.web.http.CookieSerializer
     * 配置cookie作用域
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
        //作用域为xx.xymall.com
        defaultCookieSerializer.setDomainName("xymall.com");
        //cookie名字
        defaultCookieSerializer.setCookieName("XYSESSION");
        return defaultCookieSerializer;
    }

    /**
     * @author XY
     * @date 2020/10/22 15:19
     * @return org.springframework.data.redis.serializer.RedisSerializer
     * 配置序列化器
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }
}
